/**
 * @ author: 汪孟苹
 */
define(['jquery','bbcare'],function($,$bb){
	var servers = {};
	var URL = $bb.baseUrl("followapp");
	var flag; // 问卷中是否配置了"table_relation"题型

	/**
	 * 处理患者基本信息
	 */
	servers.handleInfo = function(info){
		info.sex = info.gender == "F" ? "女" : info.gender == "M" ? "男" : "暂无";
		info.pregnancyWeek = parseInt(info.pregnancyDay / 7) + "周" + (info.pregnancyDay % 7) + "天";
		return info;
	}

	/**
	 * 牙齿自我记录查询接口
	 */
	servers.ajaxToothRecords = function(params,callback){
		$bb.ajax({
			url: URL + "webapi/service/qryToothRecords",
			data:JSON.stringify({
				data : {
					"userId":params.info.userId,
					"queueId":params.info.queueId,
					"busiType":"A0701"
				}
			}),
			success: function(data){
				if(data.success){
					callback(data.data);
				}else{
					$bb.toastShow(data.msg ? data.msg : "牙齿自我记录查询出错！");
				}
			}
		});
	}

	/**
	 * 处理出牙记录数据
	 */
	servers.handleTooth = function(list){
		var data = $bb.code.getDeCodes();
		var obj = {
			"tooth00":{ "deCode":data.tooth00,"name":"开始出牙时间"},
			"tooth01":{ "deCode":data.tooth01,"name":"上切牙左"},
			"tooth02":{ "deCode":data.tooth02,"name":"上切牙右"},
			"tooth03":{ "deCode":data.tooth03,"name":"上侧切牙左"},
			"tooth04":{ "deCode":data.tooth04,"name":"上侧切牙右"},
			"tooth05":{ "deCode":data.tooth05,"name":"上第一磨牙左"},
			"tooth06":{ "deCode":data.tooth06,"name":"上第一磨牙右"},
			"tooth07":{ "deCode":data.tooth07,"name":"上乳尖牙左"},
			"tooth08":{ "deCode":data.tooth08,"name":"上乳尖牙右"},
			"tooth09":{ "deCode":data.tooth09,"name":"上第二磨牙左"},
			"tooth10":{ "deCode":data.tooth10,"name":"上第二磨牙右"},
			"tooth11":{ "deCode":data.tooth11,"name":"下第二磨牙左"},
			"tooth12":{ "deCode":data.tooth12,"name":"下第二磨牙右"},
			"tooth13":{ "deCode":data.tooth13,"name":"下乳尖牙左"},
			"tooth14":{ "deCode":data.tooth14,"name":"下乳尖牙右"},
			"tooth15":{ "deCode":data.tooth15,"name":"下第一磨牙左"},
			"tooth16":{ "deCode":data.tooth16,"name":"下第一磨牙右"},
			"tooth17":{ "deCode":data.tooth17,"name":"下侧切牙左"},
			"tooth18":{ "deCode":data.tooth18,"name":"下侧切牙右"},
			"tooth19":{ "deCode":data.tooth19,"name":"下切牙左"},
			"tooth20":{ "deCode":data.tooth20,"name":"下切牙右"},
		};
		if( list.length > 0 ){
			for (var i = 0; i < list.length; i++) {
				for(var key in obj){
					if( obj[key].deCode == list[i].deCode ){
						obj[key].value = list[i].quesValue;
						break;
					}
				}
			}
		}
		return obj;
	}

	return servers;
});